<template>
	<view class="container">
		<view class="tabs">
			<u-tabs lineColor="#3072F6" keyName="name" :scrollable="false" :list="tabs" @click="onClickTabs"></u-tabs>
		</view>
		<view class="number">
			<view class="text">团队人数：{{ total }}人</view>
		</view>
		<view class="people" v-if="child.length > 0">
			<view class="item" v-for="(item, index) in child" :key="index">
				<view class="head">
					<u--image shape="circle" :showLoading="true" :src="item.user.avatar.file_path" width="52px"
						height="52px">
					</u--image>
				</view>
				<view class="info">
					<view class="nickname">{{ item.user.nickName }}</view>
					<view class="date">{{ item.create_time }}</view>
				</view>
			</view>
		</view>
		<view class="people" v-else>
			<u-empty text="暂无团队记录" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty>
		</view>
	</view>
</template>

<script>
	import {
		team
	} from '@/api/dealer.js';
	import {
		config
	} from '@/api/system.js';
	export default {
		data() {
			return {
				total: 0,
				tabs: [],
				child: [],
				dealer: [],
				index: 1,
				level: 1,
				conf: {},
				is_reach: false,
				page: 1,
			};
		},
		onShow() {
			this.getTeam();
		},
		onLoad() {
			this.getConfig()
		},
		onReachBottom() {
			let _this = this
			_this.is_reach = true
			_this.page = _this.page + 1
			_this.getTeam();
		},
		methods: {
			getConfig() {
				config({
						key: 'dealer'
					})
					.then(res => {
						this.conf = res.data.config;
						let tabs = []
						if (this.conf.level == 2) {
							tabs = [{
									name: '一级团队',
									value: 1
								},
								{
									name: '二级团队',
									value: 2
								}
							]
						}
						if (this.conf.level == 3) {
							tabs = [{
									name: '一级团队',
									value: 1
								},
								{
									name: '二级团队',
									value: 2
								},
								{
									name: '三级团队',
									value: 3
								}
							]
						}
						this.tabs = tabs
					})
					.catch(err => {});
			},
			onClickTabs(e) {
				this.index = e.value;
				this.page = 1
				this.getTeam();
			},
			getTeam() {
				let _this = this
				team({
						level: this.index,
						page: _this.page
					})
					.then(res => {
						if (_this.is_reach) {
							_this.child = [..._this.child, ...res.data.list.data]
						} else {
							_this.child = res.data.list.data
						}
						_this.is_reach = false
						_this.dealer = res.data.dealer;
						_this.total = res.data.list.total
					})
					.catch(err => {});
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.people {
		.item {
			display: flex;
			flex-direction: row;
			align-items: center;
			border-bottom: 1rpx solid #ecedef;

			.head {
				margin: 20rpx;
				margin-left: 40rpx;
			}

			.info {
				.nickname {
					font-size: 30rpx;
					color: #333333;
					margin-bottom: 10rpx;
				}

				.date {
					font-size: 24rpx;
					color: #999999;
				}
			}
		}
	}

	.number {
		background-color: #f5f6f7;

		.text {
			font-size: 28rpx;
			color: #999999;
			padding: 30rpx;
		}
	}
</style>
